<?php

namespace app\common\model;

use think\Db;
use think\Model;

class Project extends Model
{
    protected $pk="pro_id";
    protected $table="st_project";
    public function editProject($data){
        $saveProject=$this->save($data,$data['pro_id']);
        if($saveProject){
            return [
                'valid'=>1,
                'msg'=>'课程编辑成功'
            ];
        }else{
            return [
                'valid'=>0,
                'msg'=>'课程编辑失败'
            ];
        }
    }
    public function saveProject($data){
        $checkName=$this->where("pro_name",$data['pro_name'])->find();
        if($checkName){
            return [
                'valid'=>0,
                'msg'=>'课程名称已存在'
            ];
        }
        $checkSort=$this->where("pro_sort",$data['pro_sort'])->find();
        if($checkSort){
            return [
                'valid'=>0,
                'msg'=>'课程排序已存在'
            ];
        }
        $data['pro_creat_time']=time();
        $saveProject=$this->save($data);
        if($saveProject){
           return [
               'valid'=>1,
               'msg'=>'课程添加完成'
           ];
        }else{
           return [
               'valid'=>0,
               'msg'=>'课程添加失败'
           ];
        }
    }
    public function getProjectList(){
        $list=Db::table('st_project')->select();
        foreach ($list as $k=>$v){
            $sonVideo=Db::name('video')->where('video_pro_id',$v['pro_id'])->count();
            $list[$k]['sonvideo']=$sonVideo;
        }
        return $list;
    }
    public function getProject($id){
        $project=Db::table('st_project')->find();
        return $project;
    }
}
